<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : mjuz.xsl
    Created on : 28. duben 2011, 18:30
    Author     : newohybat newohybat@gmail.com
    Description:
        Stylesheet to transform source data(html) to internal representation (xml - internalConcerts)
-->

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://code.google.com/p/kalkon/internalConcerts">

    <xsl:output method="xml"
                encoding="UTF-8"
                indent="yes"
                media-type="text/xml"/>


<!-- Create concerts  -->
    <xsl:variable name="year" select="substring(//h2[1],string-length(//h2[1])-3,4)"/>

    <xsl:template match="/html">
        <concerts>
            <xsl:attribute name="id"><xsl:text>Music_Club_mju:z@KalKon</xsl:text></xsl:attribute>
            <xsl:apply-templates select="descendant::p[@class='programHead']"/>
        </concerts>
    </xsl:template>
<!--  Create concert  -->
    <xsl:template match="//p[@class='programHead']">
        <concert>
            <title><xsl:value-of select="following-sibling::h2[1]"/></title>
            <description><xsl:value-of select="normalize-space(following-sibling::p[1])"/></description>
            <location>[mju:z] Restaurant &amp; Music Club, Moravské náměstí 15, Brno</location>
            <xsl:apply-templates select="span[1]"/>
            <time_start><xsl:text>200000</xsl:text></time_start>
        </concert>
    </xsl:template>
<!--  Create day_start  -->
    <xsl:template match="span">
        <xsl:variable name="dateToParse" select="substring-after(.,' ')"/>
        <xsl:variable name="day">
            <xsl:choose>
                <xsl:when test="string-length(substring-before($dateToParse,'.'))&lt;2">
                    <xsl:value-of select="concat('0',substring-before($dateToParse,'.'))"/>
                </xsl:when>
                <xsl:otherwise><xsl:value-of select="substring-before($dateToParse,'.')"/></xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="month">
            <xsl:choose>
                <xsl:when test="string-length(substring-after($dateToParse,'.'))&lt;2">
                    <xsl:value-of select="concat('0',substring-after($dateToParse,'.'))"/>
                </xsl:when>
                <xsl:otherwise><xsl:value-of select="substring-after($dateToParse,'.')"/></xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <day_start><xsl:value-of select="concat($year,$month,$day)"/></day_start>
    </xsl:template>
</xsl:stylesheet>
